package com.markan.facebook.group.service;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.markan.facebook.utl.MknJSONUtil;

public class GroupJSONParser {
	
	public List<GroupVO> getGroupList(JSONObject jsonObj) throws Exception {
		
		List<GroupVO> groupList = new ArrayList<GroupVO>();
		JSONArray groupsJSONArr = MknJSONUtil.getObject2JSONArray( jsonObj.get("data"));
		for(int i=0, groupSize = groupsJSONArr.size(); i<groupSize; i++ ) {
			JSONObject groupJsonObj = (JSONObject) groupsJSONArr.get(i);
			
			int version = MknJSONUtil.getObject2Integer(groupJsonObj.get("version"));
			String name = (String) groupJsonObj.get("name");
			String id = (String) groupJsonObj.get("id");
			boolean administrator = MknJSONUtil.getObject2Booelan(groupJsonObj.get("administrator"));
			int bookmarkOrder = MknJSONUtil.getObject2Integer(groupJsonObj.get("bookmark_order"));
			
			GroupVO group = new GroupVO();
			group.setVersion(version);
			group.setName(name);
			group.setId(id);
			group.setAdministrator(administrator);
			group.setBookmarkOrder(bookmarkOrder);
			
			groupList.add(group);
			
		}
		return groupList;
	}
}
